﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YXShop.IDAL.Accessories;
using System.Data;
using System.Data.SqlClient;

namespace YXShop.SQLServerDAL.Accessories
{
    public class QuestionnaireIp:IQuestionnaireIp
    {
        #region "Database Operation"
        /// <summary>
        /// 添加IP
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(YXShop.Model.Accessories.QuestionnaireIp model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [yxs_questionnaireIp](");
            strSql.Append("[quest_id],[ip_start],[ip_end],[ip_lx])");
            strSql.Append("values(");
            strSql.Append("@questid,@start,@end,@lx) Select scope_IDENTITY()");
            SqlParameter[] parameters = (SqlParameter[])this.ValueParams(model);
            object obj = ChangeHope.DataBase.SQLServerHelper.GetSingle(strSql.ToString(),parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        public void Update(YXShop.Model.Accessories.QuestionnaireIp model)
        {
          
        }

        public void Delete(int id)
        {
            throw new NotImplementedException();
        }
        #endregion

        #region "Data Load"
        public YXShop.Model.Accessories.QuestionnaireIp GetModelById(int id)
        {
            throw new NotImplementedException();
        }

        public List<YXShop.Model.Accessories.QuestionnaireIp> GetAllModel()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region  "Other function"

        public IDataParameter[] ValueParams(YXShop.Model.Accessories.QuestionnaireIp model)
        {
            SqlParameter[] parameters=new SqlParameter[5];
            parameters[0] = new SqlParameter("@id",SqlDbType.Int,4);
            parameters[1] = new SqlParameter("@questid",SqlDbType.Int,4);
            parameters[2] = new SqlParameter("@start",SqlDbType.VarChar,50);
            parameters[3] = new SqlParameter("@end",SqlDbType.VarChar,50);
            parameters[4] = new SqlParameter("@lx",SqlDbType.VarChar,50);
            parameters[0].Value = model.Ip_id;
            parameters[1].Value = model.Questid;
            parameters[2].Value = model.Ipstart;
            parameters[3].Value = model.Ipend;
            parameters[4].Value = model.Iplx;
            return parameters;
        }
        #endregion
    }
}
